<?php

namespace app\common\model\modify;

use think\Model;


class Review extends Model
{

    

    

    // 表名
    protected $name = 'modify_review';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'state_text',
        'child',
    ];
    public function getChildAttr($v, $d)
    {
        return self::where('m_id', $d['id'])->field('id,content,images')->find() ?? [];
    }

    
    public function getStateList()
    {
        return ['0' => __('State 0'), '1' => __('State 1'), '2' => __('State 2')];
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function user()
    {
        return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function order()
    {
        return $this->belongsTo('Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function modify()
    {
        return $this->belongsTo('app\common\model\Modify', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
